import torch
import torch.nn as nn

# 创建线性层：输入维度5，输出维度3
linear = nn.Linear(in_features=5, out_features=3, bias=True)

# 输入张量：batch_size=2，特征维度=5
x = torch.randn(2, 5)
y = linear(x)  # 输出：[2, 3]

print(f"输入形状: {x}")  # 输出：torch.Size([2, 5])
print(f"输出形状: {y}")  # 输出：torch.Size([2, 3])
print(f"权重矩阵形状: {linear.weight}")  # 输出：torch.Size([3, 5])
print(f"偏置向量形状: {linear.bias}")  # 输出：torch.Size([3])